#pragma once

#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
#include <QByteArray>
#include <QString>
#include <QVariantMap>
#include "myLog.h"

using namespace std;


class TcpServer : public QObject
{
    Q_OBJECT
public:
    TcpServer();
    ~TcpServer();

public:   
    void init(const string& ip,const int &port);
    Q_INVOKABLE bool start();
    Q_INVOKABLE void stop();
private:
    void write(const QByteArray& msg);

public slots:
    void slot_write(const QString& msg);
    void slot_start();

private slots:
    void slot_read();

signals:  
    void signal_tcpServer(const QVariantMap& msg);
    void signal_openStatus(const QVariantMap&);

private:
    QTcpServer *tcpServer_ = nullptr;
    QTcpSocket *sSocket_ = nullptr;
    QByteArray rec_buffer_;
    string ip_;
    int port_;
};


